home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / cxref_1_4a.lha / FAQ-html.pl < prev    next >
Perl Script  |  1997-05-25  |  2KB  |  89 lines

  1. #!/usr/bin/perl
  2. #-*-perl-*-
  3.  
  4. #
  5. # Copyright Andrew M. Bishop 1996.97.
  6. #
  7. # Usage: FAQ-html.pl < FAQ > FAQ.html
  8. #
  9.  
  10. $_=<STDIN>;
  11. s/^ *//;
  12. s/ *\n//;
  13. $first=$_;
  14.  
  15. print "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n";
  16. print "<HTML>\n";
  17. print "\n";
  18. print "<HEAD>\n";
  19. print "<TITLE>$first</TITLE>\n";
  20. print "</HEAD>\n";
  21. print "\n";
  22. print "<BODY>\n";
  23. print "\n";
  24. print "<h1>$first</h1>\n";
  25.  
  26. $questions=0;
  27. $answers=0;
  28. $pre=0;
  29. $blank=1;
  30.  
  31. while(<STDIN>)
  32.   {
  33.    chop;
  34.  
  35.    s/</</g;
  36.    s/>/>/g;
  37.    s/&/&/g;
  38.    s/\"/"/g;
  39.  
  40.    next if(m/^ *=+ *$/);
  41.    next if ($_ eq "--------------------");
  42.    $pre++,$blank=0,next if($pre==1 && $_ eq "");
  43.    $blank=1,next        if($pre!=1 && $_ eq "");
  44.    $pre++ if($pre);
  45.  
  46.    if ($_ eq "--------------------------------------------------------------------------------")
  47.        {
  48.         $pre=0,print "</pre>\n" if($pre);
  49.         print "<hr>\n";
  50.         $answers++              if( $answers);
  51.         $questions=0,$answers=1 if( $questions);
  52.         $questions=1            if(!$questions && !$answers);
  53.        }
  54.    else
  55.        {
  56.         if(m/^(Section [0-9]+)/)
  57.             {
  58.              $section = $1;
  59.              $section =~ tr/ /-/;
  60.  
  61.              $pre=0,print "</pre>\n" if($pre);
  62.              print "<p><b><a href=\"#$section\">$_</a></b>\n" if($questions);
  63.              print "<h2><a name=\"$section\">$_</a></h2>\n"       if($answers);
  64.             }
  65.         else
  66.             {
  67.              if(m/^(Q [0-9]+.[0-9]+[a-z]*)/)
  68.                  {
  69.                   $question = $1;
  70.                   $question =~ tr/ /-/;
  71.  
  72.                   $blank=0,$pre=0,print "</pre>\n" if($pre);
  73.                   print "<p><a href=\"#$question\">$_</a>\n"  if($questions);
  74.                   print "<h3><a name=\"$question\">$_</a></h3>\n" if($answers);
  75.                   $pre=1,print "<pre>\n" if($answers);
  76.                  }
  77.              else
  78.                  {
  79.                   $blank=0,print "\n" if($blank);
  80.                   print "$_\n";
  81.                  }
  82.             }
  83.        }
  84.   }
  85.  
  86. print "</BODY>\n";
  87. print "\n";
  88. print "</HTML>\n";
  89.